package com.nuoniu.sibanyun.mapper.so;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.so.VAreaCalculationDetail;
import com.nuoniu.sibanyun.entity.so.VAreaCalculationMain;
import com.nuoniu.sibanyun.entity.vo.ns_staristics.ProjectBatchExecutionStatisticsVo;
import com.nuoniu.sibanyun.entity.vo.ns_staristics.ProjectExecutionStatisticsVo;
import com.nuoniu.sibanyun.entity.vo.ns_staristics.dto.ProjectExecutionStatisticsDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 面积计算-主表 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-22
 */
public interface VAreaCalculationMainMapper extends BaseMapper<VAreaCalculationMain> {

    @Select("select voucher_code from v_area_calculation_main where company_id=#{companyId} and date_format(now(), #{dateStr})=date_format(create_date, #{dateStr}) order by create_date desc limit 1")
    String getCode(Integer companyId,  String dateStr);

    @Select("select no, price, quantity, length, width, unit_area, total_area, cutting_size_length, cutting_size_width, color_name, panel, template, panel_thickness, weld_line, " +
            " grooving, open_number, bend_number from v_area_calculation_detail where company_id=#{companyId} and order_id = #{orderId}")
    List<HashMap<String, Object>> getList(Integer companyId, Integer orderId);

    /**
     * 更新 批次 完成 数量 todo
     * @param mainId
     * @param addNum
     * @param companyId
     */
    void updateCumExecuteQuantity(Long mainId, BigDecimal addNum,Integer companyId);

    /**
     * 统计项目 完成情况 todo 完善查询条件
     * @param companyId
     * @param projectExecutionStatisticsDto
     * @return
     */
    List<ProjectExecutionStatisticsVo> projectExecutionStatistics(Integer companyId,@Param("dto") ProjectExecutionStatisticsDto projectExecutionStatisticsDto);

    /**
     * 批次 完成 情况(按 项目 统计) todo 完善查询条件
     * @param companyId
     * @param projectId
     * @return
     */
    List<ProjectBatchExecutionStatisticsVo> ProjectBatchExecutionStatistics(Integer companyId,Integer projectId);
    /**
     * 批次 完成 情况 （按批次统计） todo 完善查询条件
     * @param companyId
     * @param mainId
     * @return
     */
    List<ProjectBatchExecutionStatisticsVo> ProjectBatchExecutionStatisticsFromMainId(Integer companyId,Integer mainId);




    void updatePrice(List<VAreaCalculationDetail> details);
}
